<?php

class Statistic 
{

private static $_instance = null ;
private $microTimeStart ;
private $memmoryStart ; 

    private function __construct() {}
    
    private function __clone() {}
    
    public static function getInstance()
    {
        if( null == self::$_instance) { 
            self::$_instance = new Statistic();
        }
        return self::$_instance;
    }
    
    public function setStartParams()
    {
        //xdebug_start_trace('c:/Apache/sites/lesson4.embria/logs/trace.lesson4');
        $mtime = microtime();
        $mtime = explode(" ",$mtime); 
        $this->microTimeStart = $mtime[1] + $mtime[0];
        $this->memmoryStart = memory_get_usage();
    }
    
    public function printStatistic()
    {
        $mtime = microtime(); 
        $mtime = explode(" ",$mtime); 
        $mtime = $mtime[1] + $mtime[0];
        $totaltime = ($mtime - $this->microTimeStart);
        printf ("Страница сгенерирована за %f секунд !<br>\n", $totaltime);

        $end_memory_usage = memory_get_usage();
        $total_memory_usage = $end_memory_usage - $this->memmoryStart;
        echo 'Использовано Оперативной памяти : ' . $total_memory_usage  . " байт <br>";
        if (isset($_SESSION['queryCount'])){
            $count = $_SESSION['queryCount'];
        } else {
            $count = 0 ; 
        }
        echo 'Количество запросов к БД : ' . $count ; 
        //xdebug_stop_trace(); 
    }
    
    
}